/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * Projects
 * Copyright (C) Arnaud Duval 2010 <arnaud.duval@gmail.com>
 * 
 * Projects is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Projects is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <Interval.hpp>
#include <fstream>
#include <cassert>

///@brief Default constructor
Interval::Interval()
{
    name = "new";
    distance = 0.;
}
    
///@brief Copy constructor
///@param i Interval object to copy
Interval::Interval(const Interval& i)
{
    startDateTime = i.startDateTime;
    duration = i.duration;
    name = i.name;
    distance = i.distance;
}

///@brief Constructor with arguments
///@param s start DateTime
///@param d Duration of interval
///@param n Name of the interval
Interval::Interval(DateTime s, Duration d, std::string n)
{
    startDateTime = s;
    duration = d;
    name = n;
}

///@brief Destructor
Interval::~Interval()
{
    
}

///@brief Overload of = operator
///@param i Interval object to copy
Interval& Interval::operator=(const Interval& i)
{
    startDateTime = i.startDateTime;
    duration = i.duration;
    name = i.name;
    distance = i.distance;
    
    return (*this);
}

/// GETTERS

///@brief Return interval duration
///@return Duration of the interval
Duration Interval::GetDuration() const
{
    return duration;
}

///@brief Return start DateTime
///@return Start DateTime
DateTime Interval::GetStartDateTime() const
{
    return startDateTime;
}

///@brief Return end DateTime
///@return End DateTime
DateTime Interval::GetEndDateTime() const
{
    DateTime res = startDateTime + duration;
    return res;
}

///@brief Return name
///@return Name of the interval
std::string Interval::GetName() const
{
    return name;
}

///@brief Return distance
///@return Distance in kilometers
double Interval::GetDistance() const
{
    return distance;
}

/// SETTERS
///@brief Set the interval duration
///@param d Duration value to set
void Interval::SetDuration(Duration d)
{
    duration = d;
}

///@brief Set the start DateTime
///@param s Start DateTime to set
void Interval::SetStartDateTime(DateTime s)
{
    startDateTime = s;
}

///@brief Set the name
///@param n Name to set
void Interval::SetName(std::string n)
{
    name = n;
}

///@brief Set distance
///@param d Distance value to set
void Interval::SetDistance(double d)
{
    assert(d >= 0.);
    distance = d;
}

///@brief Write to XML native file
///@param fout Reference to out file stream
void Interval::WriteXML(std::ofstream &fout)
{
    fout << "       <Interval>" << "\n";
    fout << "        <Name>" << name << "</Name>\n";
    fout << "        <StartDateTime>" << startDateTime << "</StartDateTime>\n";
    fout << "        <Duration>" << duration << "</Duration>\n";
    fout << "        <Distance>" << distance << "</Distance>\n";
    fout << "       </Interval>" << "\n";
}